package com.atguigu.tingshu.user.stragegy.impl;
import java.util.Date;
import com.google.common.collect.Maps;

import com.atguigu.tingshu.common.constant.SystemConstant;
import com.atguigu.tingshu.model.user.UserPaidAlbum;
import com.atguigu.tingshu.user.mapper.UserPaidAlbumMapper;
import com.atguigu.tingshu.user.stragegy.UpdateUserPaidRecordStrategy;
import com.atguigu.tingshu.vo.user.UserPaidRecordVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * UserPaidAlbumStrategy 专辑购买
 *
 * @author Petrichor
 * @version 2024/01/08 22:58
 **/
@Service
public class UserPaidAlbumStrategy implements UpdateUserPaidRecordStrategy {
    private final UserPaidAlbumMapper userPaidAlbumMapper;

    @Autowired
    public UserPaidAlbumStrategy(UserPaidAlbumMapper userPaidAlbumMapper) {
        this.userPaidAlbumMapper = userPaidAlbumMapper;
    }

    @Override
    public void updateUserPaidRecord(UserPaidRecordVo userPaidRecordVo) {
        // 先判断是否重新请求 查看数据库中是否存在相关数据
        LambdaQueryWrapper<UserPaidAlbum> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(UserPaidAlbum::getOrderNo,userPaidRecordVo.getOrderNo());
        long count = userPaidAlbumMapper.selectCount(lambdaQueryWrapper);
        if (count!=0){
            return;
        }
        UserPaidAlbum userPaidAlbum = new UserPaidAlbum();
        userPaidAlbum.setOrderNo(userPaidRecordVo.getOrderNo());
        userPaidAlbum.setUserId(userPaidRecordVo.getUserId());
        userPaidAlbum.setAlbumId(userPaidRecordVo.getItemIdList().get(0));
        userPaidAlbumMapper.insert(userPaidAlbum);
    }

    @Override
    public String getItemType() {
        // 1001
        return SystemConstant.ORDER_ITEM_TYPE_ALBUM;
    }
}


